<?php include __DIR__.'/public/header.php';?>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>/swfupload/swfupload.js?v=<?php echo SYS_VERSION;?>"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>/swfupload/fileprogress.js?v=<?php echo SYS_VERSION;?>"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>/swfupload/handlers.js?v=<?php echo SYS_VERSION;?>"></script>
<script type="text/javascript">
    <?php echo HTML::initupload($args, $upload_maxsize); ?>
</script>
<div class="pad-10">
    <div class="col-tab">
        <ul class="tabBut cu-li">
            <li id="tab_swf_1" <?php echo $tab_status; ?> onclick="SwapTab('swf','on','',5,1);">上传附件</li>
            <li id="tab_swf_2" onclick="SwapTab('swf','on','',5,2);">网络文件</li>
            <!--
            <li id="tab_swf_3" onclick="SwapTab('swf','on','',5,3);set_iframe('album_list','index.php?m=attachment&c=attachments&a=album_load&args=<?php echo $args?>');">图库</li>
            -->

            <li id="tab_swf_4" onclick="SwapTab('swf','on','',5,4);set_iframe('album_dir','<?php echo U('admin/upload/albumdir');?>?args=<?php echo $args?>');">目录浏览</li>
            <?php if($att_not_used != ''): ?>
            <li id="tab_swf_5" class="on icon" onclick="SwapTab('swf','on','',5,5);">未使用文件</li>
            <?php endif; ?>
        </ul>
        <div id="div_swf_1" class="content pad-10 <?php echo $div_status?>">
            <div>
                <div class="addnew" id="addnew">
                    <span id="buttonPlaceHolder"></span>
                </div>
                <input type="button" id="btupload" value="开始上传" onClick="swfu.startUpload();" />
                <div id="nameTip" class="onShow">最多上传 <font color="red"> <?php echo $file_upload_limit?></font> 个附件,单文件最大 <font color="red"><?php echo $file_size_limit?></font></div>
                <div class="bk3"></div>
                
                <div class="lh24">支持 <font style="font-family: Arial, Helvetica, sans-serif"><?php echo str_replace(array('*.',';'),array('','、'),$file_types)?></font> 格式</div><input type="checkbox" id="watermark_enable" value="1" <?php if(isset($watermark_enable) &&$watermark_enable == 1) echo 'checked'?> onclick="change_params()"> 是否添加水印
            </div> 	
            <div class="bk10"></div>
            <fieldset class="blue pad-10" id="swfupload">
            <legend>列表</legend>
            <ul class="attachment-list"  id="fsUploadProgress">    
            </ul>
            </fieldset>
        </div>
        <div id="div_swf_2" class="contentList pad-10 hidden">
        <div class="bk10"></div>
            请输入网络地址<div class="bk3"></div><input type="text" name="info[filename]" class="input-text" value=""  style="width:350px;"  onblur="addonlinefile(this)">
        <div class="bk10"></div>
        </div>    

        <!-- 图库 -->
        <!--
        <div id="div_swf_3" class="contentList pad-10 hidden">
            <ul class="attachment-list">
             <iframe name="album-list" src="#" frameborder="false" scrolling="no" style="overflow-x:hidden;border:none" width="100%" height="345" allowtransparency="true" id="album_list"></iframe>   
            </ul>
        </div>
        -->

        <div id="div_swf_4" class="contentList pad-10 hidden">
            <ul class="attachment-list">
             <iframe name="album-dir" src="#" frameborder="false" scrolling="auto" style="overflow-x:hidden;border:none" width="100%" height="330" allowtransparency="true" id="album_dir"></iframe>   
            </ul>
        </div>

        <?php if($att_not_used!='') {?>
        <div id="div_swf_5" class="contentList pad-10">
            <div class="explain-col">未处理</div>
            <ul class="attachment-list" id="album">
            <?php if(is_array($att) && !empty($att)){ foreach ($att as $_v) {?>
            <li>
                <div class="img-wrap">
                    <a onclick="javascript:album_cancel(this,'<?php echo $_v['aid']?>','<?php echo $_v['src']?>')" href="javascript:;" class="off"  title="<?php echo $_v['filename']?>"><div class="icon"></div><img width="<?php echo $_v['width']?>"  path="<?php echo $_v['src']?>" src="<?php echo $_v['fileimg']?>" title="<?php echo $_v['filename']?>"></a>
                </div>
            </li>
            <?php }}?>
            </ul>
        </div>   
        <?php }?>     
    <div id="att-status" class="hidden"></div>
     <div id="att-status-del" class="hidden"></div>
    <div id="att-name" class="hidden"></div>
<!-- swf -->
</div>
</body>
<script type="text/javascript">
//防止缓存
if ($.browser.mozilla) {
    window.onload=function(){
      if (location.href.indexOf("&rand=")<0) {
            location.href=location.href+"&rand="+Math.random();
        }
    }
}

function imgWrap(obj){
    $(obj).hasClass('on') ? $(obj).removeClass("on") : $(obj).addClass("on");
}
//点击标签切换
function SwapTab(name,cls_show,cls_hide,cnt,cur) {
    for(i=1;i<=cnt;i++){
        if(i==cur){
             $('#div_'+name+'_'+i).show();
             $('#tab_'+name+'_'+i).addClass(cls_show);
             $('#tab_'+name+'_'+i).removeClass(cls_hide);
        }else{
             $('#div_'+name+'_'+i).hide();
             $('#tab_'+name+'_'+i).removeClass(cls_show);
             $('#tab_'+name+'_'+i).addClass(cls_hide);
        }
    }
}

function addonlinefile(obj) {
    var strs = $(obj).val() ? '|'+ $(obj).val() :'';
    $('#att-status').html(strs);
}

function change_params(){
    if($('#watermark_enable').attr('checked')) {
        swfu.addPostParam('watermark_enable', '1');
    } else {
        swfu.removePostParam('watermark_enable');
    }
}

function set_iframe(id,src){
    $("#"+id).attr("src",src); 
}
//未处理文件点击时的处理，主要系设计和删除cookie
function album_cancel(obj,id,source){
    var src = $(obj).children("img").attr("path");
    var filename = $(obj).attr('title');
    if($(obj).hasClass('on')){
        $(obj).removeClass("on");
        var imgstr = $("#att-status").html();
        var length = $("a[class='on']").children("img").length;
        var strs = filenames = '';
        $.get('<?php echo U('admin/upload/swfuploadjsondel');?>?_='+Math.random()+'&aid='+id+'&src='+source+'&filename='+filename);
        for(var i=0;i<length;i++){
            strs += '|'+$("a[class='on']").children("img").eq(i).attr('path');
            filenames += '|'+$("a[class='on']").children("img").eq(i).attr('title');
        }
        $('#att-status').html(strs);
        $('#att-status').html(filenames);
    } else {
        var num = $('#att-status').html().split('|').length;
        var file_upload_limit = '<?php echo $file_upload_limit?>';
        if(num > file_upload_limit) {alert('最多可以上传'+file_upload_limit+'队列文件数量超过设定值'); return false;}
        $(obj).addClass("on");
        $.get('<?php echo U('admin/upload/swfuploadjson');?>?_='+Math.random()+'&aid='+id+'&src='+source+'&filename='+filename);
        $('#att-status').append('|'+src);
        $('#att-name').append('|'+filename);
    }
}
</script>
</html>